//
// Created by ZLY on 2025/3/29.
//

#ifndef AUDIOOUTPUT_H
#define AUDIOOUTPUT_H
#define MAX_AUDIO_BUFFER_SIZE (192000)
#include <cstdint>

#include "AVFrameQueue.h"
#include "Log.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_audio.h>
#include <thread>
typedef struct AudioParams {
    int freq;
    int channels;
    int64_t channel_layout;
    enum AVSampleFormat sample_format;
    int frame_size;

} AudioParams;

class AudioOutput {
public:
    AudioOutput(const SDL_AudioSpec &audio_params, AVFrameQueue *frame_queue);

    ~AudioOutput();

    int Init();

    int DeInit();

    void StartPlay();

    void PlayAudio();

private:
    SDL_AudioSpec src_target_; //解码参数
    SDL_AudioSpec dst_target_; //实际输出格式
    SDL_AudioStream *audio_stream_;
    SDL_AudioDeviceID audio_device_;
    AVFrameQueue *frame_queue_;
    bool running_;
    std::thread play_thread_;
};


#endif //AUDIOOUTPUT_H
